const config = require("../../config");

Page({

    data: {
        courseId: 0,
        courseList: {},
      
    },
    onLoad: function (options) {
        console.log(options);
        if(options.courseId == null){
          this.getAllCourserByOne()
        }
        else{
          this.setData({
            courseId: options.courseId
        });
        this.getAllCourser( options.courseId);
        }
        
    },

    getAllCourserByOne: function (courseId) {
      var that = this;
      wx.request({
          url: `http://127.0.0.1:8080/coursevideo/${config.userId}/likesVideo`,
          method: "GET",
          header: {
              "Content-Type": "application/json",
          },
          success: function (res) {
              console.log(res);
              that.setData({
                  courseList: res.data.data
              })
          },
          fail: function (res) {
              console.log(res);
          }
      });
  },
    getAllCourser: function (courseId) {
        var that = this;
        wx.request({
            url: `http://127.0.0.1:8080/coursevideo/${config.userId}/list?courseId=${courseId}`,
            method: "GET",
            header: {
                "Content-Type": "application/json",
            },
            success: function (res) {
                console.log(res);
                that.setData({
                    courseList: res.data.data
                })
            },
            fail: function (res) {
                console.log(res);
            }
        });
    }
})